#include <iostream>
#include <vector>
#include <string>

using namespace std;

bool prost(int numb) {
    for (int i = 2; i < numb; i++) {
        if (numb % i == 0) {
            return false;
        }
    }
    return true;
}

int nearestProst(int numb) {
    if (prost(numb)) {
        return numb;
    }
    else {
        int count = 1;
        while (count < numb) {
            int numbUp = numb + count;
            int numbDown = numb - count;

            bool isNumbUp = prost(numbUp);
            bool isNumbDown = prost(numbDown);

            if (isNumbUp && isNumbDown) return numbDown;
            else if (isNumbUp && !isNumbDown) return numbUp;
            else if (isNumbDown && !isNumbUp) return numbDown;

            count++;
        }
    }
    return -1;
}

pair<bool, string> toInput() {
    string input;
    getline(cin, input);

    vector<string> numbers = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
    string numb = "";

    vector<string> userInput;
    size_t pos = 0;
    while ((pos = input.find(' ')) != string::npos) {
        userInput.push_back(input.substr(0, pos));
        input.erase(0, pos + 1);
    }
    userInput.push_back(input);

    for (size_t i = 0; i < userInput.size(); i++) {
        try {
            for (size_t j = 0; j < numbers.size(); j++) {
                if (userInput[i] == numbers[j]) {
                    numb += to_string(j);
                }
            }
        }
        catch (...) {
            return { false, "" };
        }
    }

    if (numb[0] == '0' || numb.size() != 3) {
        return { false, "" };
    }
    return { true, numb };
}

int main() {
    pair<bool, string> output = toInput();
    bool flag = output.first;
    string userInput = output.second;
    if (flag) {
        cout << nearestProst(stoi(userInput)) << endl;
    }
    else {
        cout << "Wrong input" << endl;
    }
    return 0;
}